#include <stdio.h>
#include <utility>
#include <algorithm>

static std::pair<int,int> intervals[50000];

int solve()
{
    int n;
    if (scanf("%d", &n) != 1 || n <= 0)
        return 0;

    for (int i = 0; i < n; i++)
        scanf("%d %d", &intervals[i].first, &intervals[i].second);

    std::sort(intervals + 0, intervals + n);
    int k = 0;
    for (int i = 1; i < n; i++)
    {
        if (intervals[i].first > intervals[k].second)
            intervals[++k] = intervals[i];
        else
            intervals[k].second = std::max(intervals[k].second, 
                                           intervals[i].second);
    }
    for (int i = 0; i <= k; i++)
        printf("%d %d\n", intervals[i].first, intervals[i].second);
    return 1;
}

int main()
{
    while (solve());
    return 0;
}